<template>
  <div>
    <el-card>
      <el-form :inline="true" :model="formInline" class="demo-form-inline">
        <el-form-item label="Approved by">
          <el-input v-model="formInline.user" placeholder="Approved by" />
        </el-form-item>
        <el-form-item label="Activity zone">
          <el-select v-model="formInline.region" placeholder="Activity zone">
            <el-option label="Zone one" value="shanghai" />
            <el-option label="Zone two" value="beijing" />
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="onSubmit">Query</el-button>
        </el-form-item>
      </el-form>
      <el-table :data="tableList" border style="width: 100%">
        <el-table-column prop="date" label="Date" width="180" />
        <el-table-column prop="name" label="Name" width="180" />
        <el-table-column prop="address" label="Address" />
        <el-table-column label="operate">
          <template #default="{ row }">
            <el-button type="primary" @click="showEdit(row)">edit</el-button>
            <el-button type="danger" @click="handleDelete">delete</el-button>
          </template>
        </el-table-column>
      </el-table>
      <fs-pagination @getTableList="getTableList" v-model:pageQuery="pageQuery" />
    </el-card>
    <table-edit ref="edit" @getTableList="getTableList" />
  </div>
</template>
<script setup>
import { reactive, ref } from "vue";
import TableEdit from "./components/TableEdit.vue";
import { ElMessage, ElMessageBox } from "element-plus";
import {usePageQuery} from "@/hooks";
import {getList} from '@/api/demo'
const pageQuery = usePageQuery();
const edit = ref(null);
const formInline = reactive({
  user: "",
  region: "",
});
const tableList = reactive([]);
const getTableList = async () => {
  tableList.splice(0)
  const res = await getList(pageQuery)
  pageQuery.total=res.total
  tableList.push(...res.list)
};
getTableList();
const onSubmit = () => {
  console.log("submit!");
};
const showEdit = (row) => {
  edit.value.showEdit(row);
};
const handleDelete = () => {
  ElMessageBox.confirm(
    "proxy will permanently delete the file. Continue?",
    "Warning",
    {
      confirmButtonText: "OK",
      cancelButtonText: "Cancel",
      type: "warning",
    }
  )
    .then(() => {
      ElMessage({
        type: "success",
        message: "Delete completed",
      });
    })
    .catch(() => {
      ElMessage({
        type: "info",
        message: "Delete canceled",
      });
    });
};
</script>
